#链接
[http://pat.zju.edu.cn/contests/pat-a-practise/1037]
#思路
- 将两个list排序
- 分别从两个list依次对应相乘,直到结果为负,将之前的结果相加
- 将两个list翻转,重复上一个过程
#代码样例1
2
3
4
5
6
7
8
9
10
11
12
13
14n = raw_input()
a = [int(x) for x in raw_input().split()]
n = raw_input()
b = [int(x) for x in raw_input().split()]
a.sort()
b.sort()
total=0
for i in range(min(len(a),len(b))):
if a[i]<0 and b[i]<0:
total = total + a[i] * b[i]
for i in range(min(len(a),len(b))):
if a[len(a)-1-i]>0 and b[len(b)-1-i]>0:
total = total + a[len(a)-1-i] * b[len(b)-1-i]
print total